package com.wang.designpattern.flyweight;

public class Client {

    public static void main(String[] args) {
        // 创建一个工厂类
        WebSiteFacotry facotry = new WebSiteFacotry();

        // 新闻形式
        WebSite webSite1 = facotry.getWebSiteCategory("新闻");
        webSite1.use(new User("wang"));

        // 博客
        WebSite webSite2 = facotry.getWebSiteCategory("博客");
        webSite2.use(new User("wang1"));


        // 新闻形式
        WebSite webSite3 = facotry.getWebSiteCategory("新闻");
        webSite3.use(new User("wang2"));

        // 博客
        WebSite webSite4 = facotry.getWebSiteCategory("博客");
        webSite4.use(new User("wang"));

        System.out.println("当前网站数量:" + facotry.getWebSiteCount());

        // 如果Integer.valueOf(x) x在-128 --- 127之间，就是使用享元模式返回，如果不在，就创建新的Integer(new)
        Integer x = Integer.valueOf(127);
        Integer y = new Integer(127);
        Integer z = Integer.valueOf(127);
        Integer w = new Integer(127);
        Integer v = Integer.getInteger("127");
        Integer u = Integer.parseInt("127");
        System.out.println(x.equals(y));// true
        System.out.println(x == y);// false
        System.out.println(x == z);// true
        System.out.println(w == x);// false
        System.out.println(w == y);// false
        System.out.println(x == v);// false
        System.out.println(x == u);// true


        Integer a = Integer.valueOf(128);
        Integer b = Integer.valueOf(128);
        System.out.println(a == b);// false
    }
}
